package ar.edu.itba.it.pdc.protocol;

import ar.edu.itba.it.pdc.protocol.exception.InvalidPOP3FormatException;

public class ValidPOP3Request extends POP3Request {
	
	public static enum Type {
		QUIT,
		USER,
		PASS,
		STAT,
		LIST,
		RETR,
		DELE,
		NOOP,
		RSET;
		
		public static Type get(String name) {
			return Type.valueOf(name.trim().toUpperCase());
		}
	}
	
	private Type type;
	private String arguments;
	
	public ValidPOP3Request(String command){
		
		if(command == null)
			throw new InvalidPOP3FormatException("End of the stream.");
		
		try {
			String[] parts = command.split(" ", 2);
			
			this.type = Type.get(parts[0]);
			
			if(parts.length > 1)
				this.arguments = parts[1];
			
		} catch(Exception e) {
			throw new InvalidPOP3FormatException("The string is not a POP3 Request.");
		}
	}
	
	public boolean is(Type type){
		return this.type.equals(type);
	}

	public Type getType() {
		return type;
	}

	protected void setType(Type type) {
		this.type = type;
	}

	public String getArguments() {
		return arguments;
	}

	protected void setArguments(String arguments) {
		this.arguments = arguments;
	}

	public boolean isValid() {
		return true;
	}
}
